package com.gateway.springboot.starter.client.common.config;

import com.gateway.client.core.register.GatewayClientRegisterRepositoryFactory;
import com.gateway.register.client.api.GatewayClientRegisterRepository;
import com.gateway.register.common.config.GatewayRegisterCenterConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: api-gateway
 * @description:
 * @author: YuKai Fan
 * @create: 2025/1/29 23:27
 **/
@Configuration
@ConditionalOnProperty(value = "gateway.register.enabled", matchIfMissing = true, havingValue = "true")
public class GatewayClientCommonBeanConfiguration {

    /**
     * Register the register repository for http client bean post processor.
     *
     * @param config the config
     * @return the client register repository
     */
    @Bean
    public GatewayClientRegisterRepository gatewayClientRegisterRepository(final GatewayRegisterCenterConfig config) {
        return GatewayClientRegisterRepositoryFactory.newInstance(config);
    }

    /**
     * gateway Register Center Config.
     *
     * @return the Register Center Config
     */
    @Bean
    @ConfigurationProperties(prefix = "gateway.register")
    public GatewayRegisterCenterConfig gatewayRegisterCenterConfig() {
        return new GatewayRegisterCenterConfig();
    }

}
